<template>
	<view>
		<view class="top">
			<view class="money">
				<view class="">
					总工资:
				</view>
				<view class="" style="font-size: 70rpx;font-weight: 600;">
					￥{{money}}
				</view>

			</view>

			<view class="" @click="show = true" style="color: white; text-align: right;margin: 20rpx;">
				{{time}}>
			</view>
		</view>




		<view class="">
			<u-search placeholder="请输入姓名" v-model="userName" shape="square" :showAction="false"></u-search>
		</view>

		<view class="u-page">
			<u-list >
				<u-list-item v-for="(item, index) in data" :key="index">
					<u-cell>
						<template slot='label'>
							<view class="time">
								<view class="">
									{{item.userName}}
								</view>

								<view class="">
									计件:{{item.num}}
								</view>

								<view class="">
									总工资:{{item.num*3}}
								</view>
							</view>
						</template>
					</u-cell>
				</u-list-item>
			</u-list>
		</view>


			<template>
				<view>
					<u-datetime-picker format="yyyy-MM" :show="show" mode="year-month" @confirm="confirm"></u-datetime-picker>
				</view>
			</template>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userName: "",
				money: 0,
				data: [],
				show: false,
				time: ""
			}
		},
		methods: {

			confirm(e) {
				console.log(e)
				this.time = this.timestampToTime(e.value)
				this.show = false
				this.getMoney()
			},

			getMoney() {
				this.value1 = this.timestampToTime(Date.now())
				var that = this
				this.api.post("/employee/selectMoney", {
					companyId: that.$store.state.myCompanyId,
					time: that.time,
					userName: that.userName
				}).then(res => {
					console.log(res.data)
					that.data = res.data
					var total = 0
					for (let i = 0; i < res.data.length; i++) {
						total = total + res.data[i].num * 3
					}
					that.money = total
					console.log(res);
				})
			},
			timestampToTime(timestamp) {
				// 时间戳为10位需*1000，时间戳为13位不需乘1000
				var date = new Date(timestamp);
				var Y = date.getFullYear() + "-";
				var M =
					(date.getMonth() + 1 < 10 ?
						"0" + (date.getMonth() + 1) :
						date.getMonth() + 1);

				return Y + M
			},


		},
		watch: {
			userName(newValue, oldValue) {
				this.getMoney()
			},
		},
		onLoad() {
			this.time = this.timestampToTime(Date.now())
			this.getMoney()
		}
	}
</script>

<style>
	.time {
		display: flex;
		justify-content: space-between;
	}

	.clothes {
		display: flex;
		justify-content: space-between;
	}

	.top {
		width: 100%;
		height: 300rpx;
		background-color: #333333;
	}

	.money {
		height: 200rpx;
		width: 100%;
		background-color: #333333;
		display: flex;
		justify-content: center;
		align-items: center;
		color: white;
	}

	.tab {
		width: 100%;
		background-color: #333333;
	}
</style>
